package com.costaccounting.base.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.costaccounting.common.annotation.Log;
import com.costaccounting.common.core.controller.BaseController;
import com.costaccounting.common.core.domain.AjaxResult;
import com.costaccounting.common.enums.BusinessType;
import com.costaccounting.base.domain.ZsCategoryPersonConfig;
import com.costaccounting.base.service.IZsCategoryPersonConfigService;
import com.costaccounting.common.utils.poi.ExcelUtil;
import com.costaccounting.common.core.page.TableDataInfo;

/**
 * 人员类目分配配置Controller
 * 
 * @author H
 * @date 2021-11-06
 */
@RestController
@RequestMapping("/base/categoryPersonConfig")
public class ZsCategoryPersonConfigController extends BaseController
{
    @Autowired
    private IZsCategoryPersonConfigService zsCategoryPersonConfigService;

    /**
     * 查询人员类目分配配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ZsCategoryPersonConfig zsCategoryPersonConfig)
    {
        startPage();
        List<ZsCategoryPersonConfig> list = zsCategoryPersonConfigService.selectZsCategoryPersonConfigList(zsCategoryPersonConfig);
//        for (int i = 0; i < list.size(); i++) {
//            list.get(i).set
//        }
        for (ZsCategoryPersonConfig categoryPersonConfig : list) {
            String remark = categoryPersonConfig.getRemark();
            String[] remarks = remark.split("msmsm");
            categoryPersonConfig.setLeaderName(remarks[0]);
            categoryPersonConfig.setCategoryName(remarks[1]);
            categoryPersonConfig.setBuildingName(remarks[2]);
        }
        return getDataTable(list);
    }

//    /**
//     * 查询人员类目分配配置列表
//     */
//    @PreAuthorize("@ss.hasPermi('base:categoryPersonConfig:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(ZsCategoryPersonConfig zsCategoryPersonConfig)
//    {
//        List<ZsCategoryPersonConfig> list = zsCategoryPersonConfigService.selectList(zsCategoryPersonConfig);
//        return getDataTable(list);
//    }

    /**
     * 导出人员类目分配配置列表
     */
    @Log(title = "人员类目分配配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZsCategoryPersonConfig zsCategoryPersonConfig)
    {
        List<ZsCategoryPersonConfig> list = zsCategoryPersonConfigService.selectZsCategoryPersonConfigList(zsCategoryPersonConfig);
        ExcelUtil<ZsCategoryPersonConfig> util = new ExcelUtil<ZsCategoryPersonConfig>(ZsCategoryPersonConfig.class);
        return util.exportExcel(list, "人员类目分配配置数据");
    }

    /**
     * 获取人员类目分配配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return zsCategoryPersonConfigService.getInfo(id);
//        return AjaxResult.success(zsCategoryPersonConfigService.selectZsCategoryPersonConfigById(id));
    }

    /**
     * 新增人员类目分配配置
     */
    @Log(title = "人员类目分配配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsCategoryPersonConfig zsCategoryPersonConfig)
    {
        return toAjax(zsCategoryPersonConfigService.insertZsCategoryPersonConfig(zsCategoryPersonConfig));
    }

    /**
     * 修改人员类目分配配置
     */
    @Log(title = "人员类目分配配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsCategoryPersonConfig zsCategoryPersonConfig)
    {
        return toAjax(zsCategoryPersonConfigService.updateZsCategoryPersonConfig(zsCategoryPersonConfig));
    }

    /**
     * 删除人员类目分配配置
     */
    @Log(title = "人员类目分配配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zsCategoryPersonConfigService.deleteZsCategoryPersonConfigByIds(ids));
    }
}
